package com.spring.lesson001.demo9;

import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author vhans
 */
public class LazyBeanTest {

    @Test
    public void LazyInitBean() {
        String beanXml = "lazyInitBean0019.xml";
        System.out.println("Spring容器启动中");
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(beanXml);
        System.out.println("Spring容器启动完毕");
        System.out.println("使用bean");
        LazyInitBean lazyInitBean = context.getBean(LazyInitBean.class);
        System.out.println("LazyInitBean:" + lazyInitBean);
    }

    @Test
    public void actualTimeDependencyLazyBean() {
        String beanXml = "actualTimeDependencyLazyBean0019.xml";
        System.out.println("Spring容器启动中");
        // 当LazyBean被依赖时,会提前创建
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(beanXml);
        System.out.println("Spring容器启动完毕");
    }
}
